package 分类.一维动规;

public class 最小花费爬楼梯 {
    /**
     定义dp数组：dp[i]为爬到第i层所需要的最小花费
     链接：https://www.nowcoder.com/practice/6fe0302a058a4e4a834ee44af88435c7?tpId=295&tqId=2366451&ru=/exam/oj&qru=/ta/format-top101/question-ranking&sourceUrl=%2Fexam%2Foj
     **/
    public static int minCostClimbingStairs (int[] cost) {
        // write code here
        int n=cost.length;
        int[] dp=new int[n+1];
        dp[0]=0;
        dp[1]=0;
        for (int i=2;i<n+1;i++){
            dp[i]=Math.min(dp[i-2]+cost[i-2],dp[i-1]+cost[i-1]);
        }
        return dp[n];
    }

    public static void main(String[] args) {
       int[] nums={2,5,20};
        System.out.println(minCostClimbingStairs(nums));
    }
}
